<template>
  <view><web-view :src="webviewUrl" @message="getMsg"></web-view></view>
</template>

<script>
import baseUrl from '@/utils/baseUrl.js' // api接口地址
import {getUrlParam} from '@/utils/common-api.js' 
export default {
  data() {
    return {
      webviewUrl: '',
      url: 'https://files.yzsheng.com/shareH5/preinspection_test/index.html?t='
    }
  },

  onLoad(op) {
    let state = ''
    if(op.state){
      state = Number(op.state)
      this.id = op.id
    }else{
      let resObj = getUrlParam(decodeURIComponent(op.q));
      state = Number(resObj.state)
      this.id = resObj.id
    }
    let token = uni.getStorageSync('token');
    if(!token){
      uni.setStorageSync('signData', {
        state:state,
        id:this.id
      });
      uni.reLaunch({
        url: '/pages_logins/login/login'
      })
      return;
    }
    /* if(process.env.NODE_ENV==='development'){
			this.url = 'https://files.yzsheng.com/shareH5/preinspection_test/index.html?t='
		}else if(process.env.NODE_ENV==='production'){
			this.url = 'https://files.yzsheng.com/shareH5/preinspection/index.html?t='
		} */
    if (baseUrl === 'https://testapi.yzsheng.com') {
      this.url = 'https://files.yzsheng.com/shareH5/preinspection_test/index.html?t='
    } else if (baseUrl === 'https://lineapi.yzsheng.com') {
      this.url = 'https://files.yzsheng.com/shareH5/preinspection/index.html?t='
    }
    switch (state) {
      // 预检
      case 3:
        this.webviewUrl = this.url + new Date().getTime() + '&state=0' + '&storeId=' + this.id + '&titleShow=1'
        break
      // 上检
      case 4:
        this.webviewUrl = this.url + new Date().getTime() + '&state=1' + '&storeId=' + this.id + '&titleShow=1'
        break
      // 质检
      case 5:
        this.webviewUrl = this.url + new Date().getTime() + '&state=2' + '&storeId=' + this.id + '&titleShow=1'
        break
      case 6:
        // 订单
        this.webviewUrl = this.url + new Date().getTime() + '&state=3' + '&order_id=' + this.id + '&titleShow=1' + '&stateOrder=openApp'
        break
      // 施工异常
      case 7:
        this.webviewUrl = this.url + new Date().getTime() + '&state=4' + '&storeId=' + this.id + '&titleShow=1'
        break
    }
  },
  methods: {
    getMsg(event) {
      let id = event.detail.data[0].order_id
      uni.redirectTo({
        url: '/pages_order/maintenanceOrderDetail/maintenanceOrderDetail?id=' + id
      })
    }
  }
}
</script>

<style></style>
